#!/bin/bash
#
# Usage:
#  startup.sh [dev|prod]
#
# Clear up the datastore.
# 
#  startup.sh [dev|prod] clear
#
# Dependencies                 Variable
# --------------------------------------------------
# google ap engine             | GAE_HOME

source './.config'

if [[ -z "$GAE_HOME" ]]; then
    echo "\$GAE_HOME not set."
    exit 1
fi

TOPDIR=''
DATASTORE='datastore'

case "$1" in
    prod) TOPDIR='gen';;
    dev) TOPDIR='src';;
    *) echo "Must specifiy 'dev' or 'prod'"
       exit 1
       ;;
esac

echo "Starting site under ${TOPDIR}"
echo "Dev console: http://localhost:8080/_ah/admin"
echo "Login: http://localhost:8080/_ah/login"
echo

if [[ -z "$2" ]]; then
    python "$GAE_HOME/dev_appserver.py" --datastore_path=datastore "${TOPDIR}"
else
    echo "Clearing the datastore"
    python "$GAE_HOME/dev_appserver.py" --clear_datastore --datastore_path=datastore "${TOPDIR}"
fi
